package com.bootcamp.javase.file;

import java.util.Scanner;

/**
 * @program: FIleCode
 * @description:
 * @author: Keyu Li
 * @create: 2021-09-08 14:58
 **/

public class UserDefinedException {
    public static void main(String[] args) throws UserException {
        System.out.println("-----------大富翁------------");
        Scanner sc = new Scanner(System.in);
//        triggerSonException();
        while (true) {
            System.out.print("how much money left? : ");
            int money = Integer.parseInt(sc.nextLine());
            try {
                triggerException(money);
            } catch (UserException e) {
                e.printStackTrace();
                System.out.println("重新输入！");
            }finally {
                System.out.println("making money!");
            }
        }
    }

    private static void triggerException(int i) throws UserException {
//        triggerSonException();
        if (i<=10) throw new UserException("Warning: 破产！");
        if (i>=1000) throw new UserRunTimeException("Warning: 其他人破产！");
    }

    private static void triggerSonException() throws UserException {
        System.out.println("Son class!");
        throw new UserException("son exception");
    }
}



class UserException extends Exception{
    public UserException() {
        super();
    }

    public UserException(String message) {
        super(message);
    }
}

class UserRunTimeException extends RuntimeException{
    public UserRunTimeException() {
        super();
    }

    public UserRunTimeException(String message) {
        super(message);
    }
}